
//加载方法
$(function (){
    //模糊查询的方法，生成表格
    $("#applyTable").bootstrapTable({
        method:"get",
        contentType:"application/json;charset=utf-8",
        url: "/DHMApply/findLike0",
        striped: true,
        pageNumber:1,
        pagination:true,
        sidePagination:"server",//设置服务端分页还是客户端分页
        pageSize:5,//页大小
        pageList:[3,5,9],//每页显示的条数
        queryParams:function (params) {
            return {
                pageNum: (params.offset / params.limit) + 1,
                pageSize:params.limit,
                productName:$("#productName").val(),
                startTime:$("#startTime").val(),
                endTime:$("#endTime").val(),
            }
        },
        columns:[
            {title:'生产计划编号',field:'applyId',align:'center'},
            {title:'计划设计人',field:'designer',align:'center'},
            {title:'登记人',field:'register',align:'center'},
            {title:'登记时间',field:'registerTime',align:'center'},
            {title:'备注',field:'remark',align:'center'},
            {title:'审核',field:'applyId',align:'center',
                formatter:function (value,row,index) {
                    let btn="<button class='btn btn-info' onclick='shenhe("+value+")'>去审核</button>";
                    return btn;
                }
            },
        ]
    })
})

//点击查询
function queryLike(){
    $("#applyTable").bootstrapTable("refresh");
}

//点击去审核
let applyId1="";
function shenhe(applyId){
    $(".div1").hide();
    $(".div2").show();
    $("#dengji").html("");
    $("#remark").html("");
    applyId1=applyId;
    document.getElementById("mApplyForm").reset();
    $.ajax({
        url: "/DHMApply/byApplyId",
        type:"get",
        data:{
            applyId:applyId,
        },
        dataType:"json",
        success:function (data){
            let tr ="";
            for (let i = 0; i < data.length; i++) {
                tr +="<tr>\n" +
                    "                <td>"+data[i].productName+"</td>\n" +
                    "                <td>"+data[i].productId+"</td>\n" +
                    "                <td>"+data[i].productDescribe+"</td>\n" +
                    "                <td class='shuliang'>"+data[i].amount+"</td>\n" +
                    "                <td>"+data[i].dFile.amoutUnil+"</td>\n" +
                    "                <td>"+data[i].dFile.realCostPrice+"</td>\n" +
                    "                <td class=\"xiaoji\">"+data[i].amount*data[i].dFile.realCostPrice+"</td>\n" +
                    "            </tr>";
            }
            $("#tbody").html(tr);

            //获取数量和小计
            let xiaoji = $(".xiaoji");
            let amounts = $(".shuliang");

            //定义总数量和总金额
            let totalCount=0;
            let totalPrice=0;
            amounts.each(function (i,e){
                totalCount+=parseInt($(e).html());
            })
            xiaoji.each(function (i,e){
                totalPrice+=parseFloat($(e).html());
            })

            $("#totalCount").html(totalCount);
            $("#totalPrice").html(totalPrice);

            //相关信息传入
            $("#dengji").html(data[0].register);
            $("#shenhe").html(parent.document.getElementsByClassName("user_name")[0].innerHTML);
            $("#remark").html(data[0].remark);
        }
    })
}

//返回列表
function fanhuiliebiao(){
    $(".div1").show();
    $(".div2").hide();
}

//通过
function adopt(){
    if (confirm("确定提交审核吗？")){
        let apply={
            checkSuggestion:$("textarea[name='checkSuggestion']").val(),
            applyId:applyId1,
            checkTag:1,
            checker:parent.document.getElementsByClassName("user_name")[0].innerHTML,
        }
        $.ajax({
            url:"/DHMApply/byApplyIdUp",
            type: "put",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(apply),
            success:function (data){
                $(".div1").show();
                $(".div2").hide();
                $("#applyTable").bootstrapTable("refresh");
            }
        })
    }
}

//不通过
function noAdopt(){
    if (confirm("确定提交审核吗？")){
        let apply={
            checkSuggestion:$("textarea[name='checkSuggestion']").val(),
            applyId:applyId1,
            checkTag:2,
            checker:parent.document.getElementsByClassName("user_name")[0].innerHTML,
        }
        $.ajax({
            url:"/DHMApply/byApplyIdUp",
            type: "put",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(apply),
            success:function (data){
                $(".div1").show();
                $(".div2").hide();
                $("#applyTable").bootstrapTable("refresh");
            }
        })
    }
}